package com.lwlk.zdk.controller.Platform;


import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lwlk.zdk.annotation.MyLog;
import com.lwlk.zdk.common.exception.handler.GlobalExceptionHandler;
import com.lwlk.zdk.enums.RetCode;
import com.lwlk.zdk.mapper.T.*;
import com.lwlk.zdk.mapper.pw.pwAssessGradeMapper;
import com.lwlk.zdk.mapper.pw.pwLoginTimeMapper;
import com.lwlk.zdk.mapper.pw.pwUserMapper;
import com.lwlk.zdk.mapper.pw.pwVehicleMapper;
import com.lwlk.zdk.mapper.sys.sysEnterpriseMapper;
import com.lwlk.zdk.mapper.task.pwTaskPlatformAssessmentStatisticsMapper;
import com.lwlk.zdk.mapper.wd.wdHfAreaMapper;
import com.lwlk.zdk.model.CommonUser;
import com.lwlk.zdk.model.Encapsulation.EncapsulationPlatform;
import com.lwlk.zdk.model.sys.sysUser;
import com.lwlk.zdk.model.T.TDisPlatform;
import com.lwlk.zdk.service.User.JoinService;
import com.lwlk.zdk.service.User.SysUserService;
import com.lwlk.zdk.service.sys.sysRoleMessageService;
import com.lwlk.zdk.service.wdHfArea.AreaService;
import com.lwlk.zdk.util.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.solr.client.solrj.request.V1toV2ApiMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.naming.Name;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.xml.crypto.Data;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@Api(value = "平台模块")
@RestController
@Transactional
@RequestMapping(value = "/join")
public class JoinController {

    private final static String port = PropUtils.getString("ports");
    private final static String Ip = PropUtils.getString("Ip");
    private final static String clientCode = PropUtils.getString("clientCode");

    private final static String filePlatformName = PropUtils.getString("filePlatformName");
    private final static String filePlatformType = PropUtils.getString("filePlatformType");
    private final static String fileTheDeveloper = PropUtils.getString("fileTheDeveloper");
    private final static String fileSoftwareSupport = PropUtils.getString("fileSoftwareSupport");
    private final static String filePlatformId = PropUtils.getString("filePlatformId");
    private final static String fileLinkman = PropUtils.getString("fileLinkman");
    private final static String fileMobile = PropUtils.getString("fileMobile");

    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);




    @Autowired
    TDisPlatformMapper tDisPlatformMapper;
    @Autowired
    TRegionMapper tRegionMapper;
    @Autowired
    TDisDictionaryMapper disDictionaryMapper;
    @Autowired
    TDisEnterpriseMapper disEnterpriseMapper;
    @Autowired
    TDisPlatformMapper disPlatformMapper;
    @Autowired
    TDisVehicleMapper disVehicleMapper;
    @Autowired
    pwLoginTimeMapper loginTimeMapper;
    @Autowired
    pwUserMapper pwUserMapper;



    @ApiOperation(value = "平台基本信息")
    @RequestMapping(value = "/platformMessage",method = RequestMethod.GET)
    public Response getPlatformMessage(){
        Response response=new Response();
        Map map=new HashMap();
        map.put("platformName",filePlatformName);
        map.put("platformType",filePlatformType);
        map.put("theDeveloper",fileTheDeveloper);
        map.put("softwareSupport",fileSoftwareSupport);
        map.put("platformId",filePlatformId);
        map.put("linkman",fileLinkman);
        map.put("mobile",fileMobile);
        response.setData(map);
        response.setCode(RetCode.SUCCESS);
        return response;
    }


    @ApiOperation(value = "添加平台信息")
    @MyLog(value = "添加平台信息")  //这里添加了AOP的自定义注解
    @RequestMapping(value = "/joinAddAccount",method = RequestMethod.POST)
    @Transactional
    public Response joinAdd(@RequestBody TDisPlatform disPlatform,HttpServletRequest request){
        Response response=new Response();
        try {
            boolean flag= listerUtil.getLister(request);
            if (flag==false){
                response.setCode(RetCode.ACCOUNT_EXIST);
                response.setMsg("此账号为监管员账号,不可进行操作");
                return response;
            }
            String areaCode=disPlatform.getAccessCode();
            Integer platformId=tDisPlatformMapper.selectMaxPlatformId()+1;
            disPlatform.setPlatformId(platformId);
            disPlatform.setDelFlag((short) 1);
            disPlatform.setCreateDate(new Date());
            int count=tDisPlatformMapper.insertSelective(disPlatform);
            response.setCode(RetCode.SUCCESS);
            response.setData(count);
            response.setMsg("执行成功");

        }catch (Exception e){
            e.printStackTrace();
        }
        return response;
    }




    @ApiOperation(value = "批量添加平台信息")
    @MyLog(value = "批量添加平台信息")
    @RequestMapping(value = "/joinAddbatch",method = RequestMethod.POST)
    public Response batch(@RequestBody EncapsulationPlatform platformList){
        Response response=new Response();
        for (TDisPlatform tDisPlatform:platformList.getDisPlatforms()){
            int count=tDisPlatformMapper.insertSelective(tDisPlatform);
        }
        return response;
    }



    @ApiOperation(value = "修改平台信息")
    @MyLog(value = "修改平台信息")  //这里添加了AOP的自定义注解
    @RequestMapping(value = "/joinUpdateAccount",method = RequestMethod.POST)
    public Response update(@RequestBody TDisPlatform disPlatform,HttpServletRequest request){
        Response response=new Response();
        try {
            Boolean flag= listerUtil.getRoleType(request);
            if (flag==false){
                response.setCode(RetCode.ACCOUNT_EXIST);
                response.setMsg("此账号为监管员账号,不可进行操作");
                return response;
            }
           Boolean flage= listerUtil.getLevel(request);
            if (flage==false) {
                response.setCode(RetCode.ACCOUNT_EXIST);
                response.setMsg("该账号没有此权限");
                return response;
            }
            int i = tDisPlatformMapper.updateByPrimaryKeySelective(disPlatform);
            response.setMsg("执行成功");
            response.setData(i);
            response.setCode(RetCode.SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
        }
        return response;
    }

    @ApiOperation(value = "接入平台展示分页展示")
    @RequestMapping(value = "/joinPlatformPaging",method = RequestMethod.GET)
    public Response getJoinPlatform(Integer page, Integer size,String account,String loginName,String mobile,String loginFlag,Integer roleType,String platformCode,Integer level,Integer platformId){
        LayuiTablePagingResult result=null;
        try {
            PageHelper.startPage(page,size);


            TDisPlatform disPlatform=new TDisPlatform();
            disPlatform.setPlatformUsername(account);
            disPlatform.setPlatformName(loginName);
            disPlatform.setLoginFlag(loginFlag);
            disPlatform.setPlatformType(roleType);
            disPlatform.setPlatformCode(platformCode);
            disPlatform.setPlatformId(platformId);
            List<Map<String,Object>>userAll=tDisPlatformMapper.searchChoice(disPlatform);
            PageInfo pageInfo=new PageInfo<>(userAll);
            result = new LayuiTablePagingResult();
            result.setCode(RetCode.SUCCESS.getCode());
            result.setMsg(RetCode.SUCCESS.getMsg());
            result.setCount(pageInfo.getTotal());
            result.setData(pageInfo.getList());
            Long totalPages = pageInfo.getTotal() / size;
            if (pageInfo.getTotal() % size != 0){
                totalPages ++;
            }
            result.setTotalPages(totalPages);
            if (level==1){
                result.setIsOperation("1");
            }else {
                result.setIsOperation("-1");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @ApiOperation(value = "接入平台展示不分页展示")
    @RequestMapping(value = "/joinPlatformNoPaging",method = RequestMethod.GET)
    public Response getJoinPlatformNoPage(String account,String loginName,String mobile,String loginFlag,Integer roleType,String platformCode,Integer level,Integer platformId){
        Response response=new Response();
        Map map=new HashMap();
        TDisPlatform disPlatform=new TDisPlatform();
        disPlatform.setPlatformUsername(account);
        disPlatform.setPlatformName(loginName);
        disPlatform.setLoginFlag(loginFlag);
        disPlatform.setPlatformType(roleType);
        disPlatform.setPlatformCode(platformCode);
        disPlatform.setPlatformId(platformId);
        List<Map<String,Object>>userAll=tDisPlatformMapper.searchChoice(disPlatform);
        userAll.add(map);
        response.setData(userAll);
        response.setCode(RetCode.SUCCESS);
        response.setMsg("执行成功");
        return response;
    }

    //=========添加平台账号不可相同===============
    @ApiOperation(value = "添加平台账号不可相同")
    @RequestMapping(value = "/Account",method = RequestMethod.GET)
    public Response getAaccount(String account){
        Response response=new Response();
        int count=tDisPlatformMapper.selectAccount(account);
        if (count>0){
            response.setCode(RetCode.ACCOUNT_EXIST);
            response.setData(account);
        }else {
            response.setCode(RetCode.ACCOUNT_USABLE);
            response.setData(account);
        }
        return response;
    }

    @ApiOperation(value = "平台详情接口")
    @RequestMapping(value = "/platformDetails",method = RequestMethod.GET)
    public Response getPlatformDetails(Integer platformId){
        Response response=new Response();
        List<Map<String,Object>>platformDetails=tDisPlatformMapper.selectByPrimaryKeyDetails(platformId);
        response.setData(platformDetails);
        response.setCode(RetCode.SUCCESS);
        response.setMsg("执行成功");
        return response;
    }

    //========平台链路情况查询接口=============
    @ApiOperation(value = "平台链路情况查询接口")
    @RequestMapping(value = "/infoByPid",method = RequestMethod.GET)
    public JSONObject getInfoByPid(Integer pId, String startTime, String endTme,String limit,String page){
        Map map=new HashMap();
        map.put("pId",String.valueOf(pId));//必选 平台id
        map.put("startTime",startTime);//开始时间yyyy-MM-dd HH:mm:ss
        map.put("endTime",endTme);//结束时间yyyy-MM-dd HH:mm:ss
        map.put("limit",limit);//页面记录数，默认为10
        map.put("page",page);//页码，默认为1
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/statistics/connectStatistic/infoByPid";
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }

    //=======平台综合统计============
    @ApiOperation(value = "平台综合统计")
    @RequestMapping(value = "/comprehensiveStatistic",method = RequestMethod.GET)
    public JSONObject getStatistics(String pId,String date){
        Map map=new HashMap();
        map.put("pId",pId);//必传 平台id
        map.put("date",date);//必传 查询时间yyyy-MM-dd
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/assessment/platform/comprehensiveStatistic";
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }


    @ApiOperation(value = "查询经营性平台或非经营性平台")
    @RequestMapping(value = "/showPlatformName",method = RequestMethod.GET)
    public Response getShowPlatformName(String platformName){
        Response response=new Response();
        List<Map<String,Object>>platform=tDisPlatformMapper.selectPlatformName(platformName);
        response.setCode(RetCode.SUCCESS);
        response.setData(platform);
        response.setMsg("执行成功");
        return response;
    }

    @ApiOperation(value = "经营性/非经营性树形数据展示")
    @RequestMapping(value = "/JoinPlatform",method = RequestMethod.GET)
    public Response getJoinPlatform(String platformCode,String platformName,Integer level){
        Response response=new Response();
     try {
         Map map=new HashMap();
         Map<String,String>headMap=new HashMap<>();
         headMap.put("clientCode",clientCode);
         map.put("regionCode","130200");
         String regionCode=null;
         if (level==1){
             regionCode= String.valueOf(platformCode).substring(0,2);
         }else if (level==2){
             regionCode= String.valueOf(platformCode).substring(0,4);
         }else if (level==3){
             regionCode= platformCode;
         }
         Integer platformType1=1;
         Integer platformType2=2;
         Integer platformType3=0;
         List<Map<String,Object>>managePlatformList=tDisPlatformMapper.selectJoinPlatform(platformName,platformType2);//经营性平台
         if (managePlatformList.size()>0){
             for (int i = 0; i < managePlatformList.size(); i++) {
                 map.put("platformType",String.valueOf(managePlatformList.get(i).get("platformType")));//车辆id，多个英文逗号分隔
                 map.put("id",String.valueOf(managePlatformList.get(i).get("platformId")));//平台id，多个英文逗号分隔
                 String url="http://"+Ip+":"+port+"/dis/v1/platform/onlineStatus";
                 String result=HttpClientUtils.doGet(url,headMap,map);
                 JSONObject json= JSONObject.parseObject(result);

                 managePlatformList.get(i).put("isOnline",json.get("result"));
             }

         }
         List<Map<String,Object>>noManagePlatformList=tDisPlatformMapper.selectJoinPlatform(platformName,platformType1);//非经营性平台
         if (noManagePlatformList.size()>0){
             for (int i = 0; i < noManagePlatformList.size(); i++) {
                 map.put("platformType",String.valueOf(managePlatformList.get(i).get("platformType")));//车辆id，多个英文逗号分隔
                 map.put("id",String.valueOf(managePlatformList.get(i).get("platformId")));//平台id，多个英文逗号分隔
                 String url="http://"+Ip+":"+port+"/dis/v1/platform/onlineStatus";
                 String result=HttpClientUtils.doGet(url,headMap,map);
                 JSONObject json= JSONObject.parseObject(result);
                 managePlatformList.get(i).put("isOnline",json.get("result"));
             }

         }
         List<Map<String,Object>>prefecturePlatformList=tDisPlatformMapper.selectJoinPlatform(platformName,platformType3);//地区性平台
         if (prefecturePlatformList.size()>0){
             for (int i = 0; i < prefecturePlatformList.size(); i++) {
                 map.put("platformType",String.valueOf(managePlatformList.get(i).get("platformType")));//车辆id，多个英文逗号分隔
                 map.put("id",String.valueOf(managePlatformList.get(i).get("platformId")));//平台id，多个英文逗号分隔
                 String url="http://"+Ip+":"+port+"/dis/v1/platform/onlineStatus";
                 String result=HttpClientUtils.doGet(url,headMap,map);
                 JSONObject json= JSONObject.parseObject(result);
                 managePlatformList.get(i).put("isOnline",json.get("result"));
             }
         }
         Map maps=new HashMap();
         maps.put("managePlatformList",managePlatformList);
         maps.put("noManagePlatformList",noManagePlatformList);
         maps.put("prefecturePlatformList",prefecturePlatformList);
         response.setCode(RetCode.SUCCESS);
         response.setData(maps);
         response.setMsg("执行成功");

     }catch (Exception e){
         e.printStackTrace();
     }
        return response;
    }


    //========获取接入码============
    @ApiOperation(value = "获取接入码")
    @RequestMapping(value = "/joinCode",method = RequestMethod.POST)
    @Transactional
    public Response code(Integer platformType,Integer AreaCode,Integer level){
        Response response=new Response();
        try {
            //判断:根据接入平台的类型不同,接入码相加
            Integer areaCode=null;
            if (level==1){
                areaCode= Integer.valueOf(String.valueOf(AreaCode).substring(0,2));
            }else if (level==2){
                areaCode= Integer.valueOf(String.valueOf(AreaCode).substring(0,4));
            }else if (level==3){
                areaCode= AreaCode;
            }
            int count=tDisPlatformMapper.joinCount(platformType,areaCode);//接入平台数
            String regionCode=String.valueOf(AreaCode).substring(0,4);
            String accessCode="";
            if (count<9){
                count=count+1;
                String ss=String.valueOf(count);
                accessCode=regionCode+"000"+ss;
            }else if (count>=10){
                count=count+1;
                String ss=String.valueOf(count);
                accessCode=regionCode+"00"+ss;
            }else if (count>=100){
                count=count+1;
                String ss=String.valueOf(count);
                accessCode=regionCode+"0"+ss;
            }else if (count<=1000){
                count=count+1;
                String ss=String.valueOf(count);
                accessCode=regionCode+ss;
            }
            response.setCode(RetCode.SUCCESS);
            response.setData(accessCode);
            response.setMsg("执行成功");
        }catch (Exception e){
            e.printStackTrace();
        }
         return response;
    }

    //========接入平台数据展示(或本平台根据平台id查询)============
    @ApiOperation(value = "接入平台数据展示(或本平台根据平台id查询)")
    @RequestMapping(value = "/showJoinAccount",method = RequestMethod.GET)
    public Response showAccount(Integer platformId){
        Response response=new Response();
        try {
            List<Map<String,Object>>sysUser=tDisPlatformMapper.selectByPlatformId(platformId);
            Integer areaCodeName=null;
            if (String.valueOf(sysUser.get(0).get("platformCode")).equals("null")){
                areaCodeName=0;
            }else {
                areaCodeName=Integer.parseInt(String.valueOf(sysUser.get(0).get("platformCode")));
            }
            String code=tRegionMapper.selectAreaCode(areaCodeName);
            sysUser.get(0).put("platformCodeName",code);
            //List<Map<String,Object>>sysUser=tDisPlatformMapper.selectByPlatformId(platformId);
            response.setMsg("执行成功");
            response.setData(sysUser);
            response.setCode(RetCode.SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
        }
        return response;
    }
    @ApiOperation(value = "接入平台数据展示(或本平台根据平台id查询)")
    @RequestMapping(value = "/showPlatformDteail",method = RequestMethod.GET)
    public Response showPlatformDetail(Integer platformId){
        Response response=new Response();
        //String platformCode="130000";
        List<Map<String,Object>>platformDetail=tDisPlatformMapper.platformDetail(platformId);
        /*Integer areaCodeName=Integer.parseInt(String.valueOf(platformDetail.get(0).get("areaCode")));
        String code=tRegionMapper.selectAreaCode(areaCodeName);
        platformDetail.get(0).put("areaCode",code);*/
        //List<Map<String,Object>>sysUser=tDisPlatformMapper.selectByPlatformId(platformId);
        response.setMsg("执行成功");
        response.setData(platformDetail);
        response.setCode(RetCode.SUCCESS);
        return response;
    }

    //========平台所属地区============
    @ApiOperation(value = "平台所属地区")
    @RequestMapping(value = "/showArea",method = RequestMethod.GET)
    public Response getShowArea(String AreaId){
        Response response=new Response();
        try {
            HashMap map=new HashMap();
            if (AreaId==null) {//查询中国的所有的省
                List areasList=tRegionMapper.selectPid();
                map.put("所属地区",areasList);
                response.setCode(RetCode.SUCCESS);
                response.setData(map);
                response.setMsg("执行成功");
            }else {//查询省管辖的市
                List areaList=tRegionMapper.selectById(AreaId);
                map.put("所属地区",areaList);
                response.setCode(RetCode.SUCCESS);
                response.setData(areaList);
                response.setMsg("执行成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return response;
        }




    //========接入平台(或本平台删除)============
    @ApiOperation(value = "删除平台信息")
    @MyLog(value = "删除平台信息")  //这里添加了AOP的自定义注解
    @RequestMapping(value = "/deleteAccount",method = RequestMethod.POST)
    public Response delete(Integer platformId,HttpServletRequest request){
      Response response=new Response();
      try {
          Boolean flag=listerUtil.getRoleType(request);
          if (flag==false){
              response.setCode(RetCode.ACCOUNT_EXIST);
              response.setMsg("此账号为监管员账号,不可进行操作");
              return response;
          }
          Boolean flage=listerUtil.getLevel(request);
          if (flage==false) {
              response.setCode(RetCode.ACCOUNT_EXIST);
              response.setMsg("该账号没有此权限");
              return response;
          }
          int count=tDisPlatformMapper.deleteByPrimaryKey(platformId);
          response.setData(count);
          response.setMsg("执行成功");
          response.setCode(RetCode.SUCCESS);

      }catch (Exception e){
          e.printStackTrace();
      }
      return response;
    }

    @ApiOperation(value = "删除平台信息")
    @MyLog(value = "删除平台信息")
    @RequestMapping(value = "/logicallyDetele",method = RequestMethod.POST)
    public Response getLogicallyDetele(Integer platformId,HttpServletRequest request){
        Response response=new Response();
        Boolean flag=listerUtil.getRoleType(request);
        if (flag==false){
            response.setCode(RetCode.ACCOUNT_EXIST);
            response.setMsg("此账号为监管员账号,不可进行操作");
            return response;
        }
        Boolean flage=listerUtil.getLevel(request);
        if (flage==false) {
            response.setCode(RetCode.ACCOUNT_EXIST);
            response.setMsg("该账号没有此权限");
            return response;
        }
        Integer i=tDisPlatformMapper.updateDelFlagStatus(platformId);
        response.setData(i);
        response.setCode(RetCode.SUCCESS);
        response.setMsg("执行成功");
        return response;
    }

    @ApiOperation(value = "批量删除平台信息(逻辑删除)")
    @MyLog(value = "批量删除平台信息(逻辑删除)")
    @RequestMapping(value = "/logicallyDeteleBatch",method = RequestMethod.POST)
    public Response getLogicallyDetele(Integer[] platformId){
        Response response=new Response();
        Integer i=null;
        for (Integer pId : platformId) {
             i=tDisPlatformMapper.updateDelFlagStatus(pId);
        }
        response.setData(i);
        response.setCode(RetCode.SUCCESS);
        response.setMsg("执行成功");
        return response;
    }

    @ApiOperation(value = "平台管理模块展示(条件查询)")
    @RequestMapping(value = "/showUserMessage",method = RequestMethod.GET)
    public LayuiTablePagingResult getUserMessage(Integer page, Integer size,String account,String loginName,String mobile,String loginFlag,Integer roleType,String platformCode){
        LayuiTablePagingResult result=null;
        try {
             PageHelper.startPage(page,size);
                TDisPlatform disPlatform=new TDisPlatform();
                disPlatform.setPlatformUsername(account);
                disPlatform.setPlatformName(loginName);
                disPlatform.setLoginFlag(loginFlag);
                disPlatform.setPlatformType(roleType);
                disPlatform.setPlatformCode(platformCode);
                List<Map<String,Object>>userAll=tDisPlatformMapper.searchChoice(disPlatform);
                PageInfo pageInfo=new PageInfo<>(userAll);
                result = new LayuiTablePagingResult();
                result.setCode(RetCode.SUCCESS.getCode());
                result.setMsg(RetCode.SUCCESS.getMsg());
                result.setCount(pageInfo.getTotal());
                result.setData(pageInfo.getList());
                Long totalPages = pageInfo.getTotal() / size;
                if (pageInfo.getTotal() % size != 0){
                    totalPages ++;
                }
                result.setTotalPages(totalPages);
                return result;
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    //===========接入平台(批量删除)==========
    @ApiOperation(value = "批量删除平台信息")
    @MyLog(value = "批量删除平台信息")  //这里添加了AOP的自定义注解
    @RequestMapping(value = "/deleteBatches",method = RequestMethod.POST)
    public Response deleteBatches(Integer[] ids){
        Response response=new Response();
        for (Integer id : ids) {
            int count=tDisPlatformMapper.deleteByPrimaryKey(id);
        }
        response.setCode(RetCode.SUCCESS);
        response.setMsg("执行成功");
        return response;
    }



    //========角色管理模块(展示)============
   /* @ApiOperation(value = "角色管理模块(展示)")
    @RequestMapping(value = "/showRoleMessage",method = RequestMethod.POST)
    public LayuiTablePagingResult getRoleMessage(Integer page,Integer size,String roleMessage){
       LayuiTablePagingResult result=null;
       try {
           PageHelper.startPage(page,size);
           if (("").equals(roleMessage)){
               List<sysRoleDetails> sysRoleDetailsList = sysRoleMessageService.search();
               PageInfo<sysRoleDetails>pageInfo=new PageInfo<>(sysRoleDetailsList);
               result = new LayuiTablePagingResult();
               result.setCode(RetCode.SUCCESS.getCode());
               result.setMsg(RetCode.SUCCESS.getMsg());
               result.setCount(pageInfo.getTotal());
               result.setData(pageInfo.getList());
               Long totalPages = pageInfo.getTotal() / size;
               if (pageInfo.getTotal() % size != 0){
                   totalPages ++;
               }
               result.setTotalPages(totalPages);
           }else {
               List<sysRoleDetails> sysRoleDetailsList = sysRoleMessageService.searchAll(roleMessage);
               PageInfo<sysRoleDetails> pageInfo = new PageInfo<>(sysRoleDetailsList);
               result = new LayuiTablePagingResult();
               result.setCode(RetCode.SUCCESS.getCode());
               result.setMsg(RetCode.SUCCESS.getMsg());
               result.setCount(pageInfo.getTotal());
               result.setData(pageInfo.getList());
               Long totalPages = pageInfo.getTotal() / size;
               if (pageInfo.getTotal() % size != 0){
                   totalPages ++;
               }
               result.setTotalPages(totalPages);
           }
       }catch (Exception e){
           e.printStackTrace();
       }
        return result;
    }*/


    //==========请求拍照接口===========
    @ApiOperation(value = "请求拍照接口")
    @MyLog(value = "请求拍照")  //这里添加了AOP的自定义注解
    @RequestMapping(value = "/platform/takePhoto",method = RequestMethod.POST)
    public JSONObject takePhoto(Integer platformId, Integer vehicleId,String param,String lensID,String size,HttpServletRequest request){
        Boolean flag=listerUtil.getRoleType(request);
        if (flag==false){
            String list = "{\"code\":1009,\"msg\":\"此账号为监管员账号,不可进行操作\"}";
            return JSONObject.parseObject(list);
        }
        Map map=new HashMap();
        map.put("param",param);
        map.put("platformId",String.valueOf(platformId));//必选 平台id
        map.put("vehicleId",String.valueOf(vehicleId));//必选 车辆id
        map.put("lensID",lensID);//必选 镜头id
        map.put("size",size);//必选 照片大小
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/platform/takePhoto";
        String result=HttpClientUtils.doPost(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }

    @ApiOperation(value = "查询字典表展示照片大小")
    @RequestMapping(value = "/showVehiclePhoto",method = RequestMethod.GET)
    public Response showVehiclePhoto(){
        Response response=new Response();
        List<Map<String,Object>>vehiclePhotoList=disDictionaryMapper.selectVehiclePhoto();
        response.setData(vehiclePhotoList);
        response.setCode(RetCode.SUCCESS);
        response.setMsg("执行成功");
        return response;
    }


    //==============展示平台,企业,车辆的id================
    @ApiOperation(value = "展示平台,企业,车辆的id")
    @RequestMapping(value = "/query_vid_pid_eid",method = RequestMethod.GET)
    public Response queryId(String vehicleNumber,String enterpriseName,String platformName){
        Response response=new Response();
        String eIds=disEnterpriseMapper.selectDimEnterpriseName(enterpriseName);//查询企业id
        String pIds=disPlatformMapper.selectDimPlatformName(platformName);//查询平台id
        String vIds=disVehicleMapper.selectDimVehicleNumber(vehicleNumber);//查询车牌号
        Map map=new HashMap();
        map.put("vehicleIds",vIds);
        map.put("enterpriseIds",eIds);
        map.put("platformIds",pIds);
        response.setData(map);
        response.setCode(RetCode.SUCCESS);
        response.setMsg("执行成功");
        return response;
    }



    @RequestMapping(method = RequestMethod.POST, value = "/getUserOnline")
    @ApiOperation(value = "获取当前在线用户数量及列表", notes = "获取当前在线用户数量及列表", httpMethod = "POST")
    public Response getUserOnline(HttpServletRequest request,HttpSession httpSession) {
        Response response=new Response();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        long ns = 1000;
        try {
            HttpSession session = request.getSession();
            ServletContext application = session.getServletContext();
            List<String> userOnlineList = (List<String>) application.getAttribute("userOnlineList");
            List<Map<String,Object>>mapList=new LinkedList<>();
            if (userOnlineList != null) {
                for (int i = 0; i < userOnlineList.size(); i++) {
                    Map map = new HashMap();
                    String sessionId = String.valueOf(userOnlineList.get(i));
                    List<Map<String, Object>> platformLoginList = loginTimeMapper.selectPlatform(sessionId);
                    if (platformLoginList.size()>0){
                        String start = String.valueOf(platformLoginList.get(0).get("loginTimeInt"));
                        Date startTime=sdf.parse(start);//登陆时间
                        Date endTime=new Date();//当前时间
                        // 获得两个时间的毫秒时间差异
                        long diff = endTime.getTime() - startTime.getTime();
                        // 计算差多少天
                        long day = diff / nd;
                        // 计算差多少小时
                        long hour = diff % nd / nh;
                        // 计算差多少分钟
                        long min = diff % nd % nh / nm;
                        // 计算差多少秒//输出结果
                        long sec = diff % nd % nh % nm / ns;
                        String loginTimeInt=day + "天" + hour + "小时" + min + "分钟"+sec+"秒";
                        map.put("id",platformLoginList.get(0).get("id"));
                        map.put("platformId",platformLoginList.get(0).get("platformId"));
                        map.put("loginTimeInt",platformLoginList.get(0).get("loginTimeInt"));
                        map.put("platformName",platformLoginList.get(0).get("platformName"));
                        map.put("linkman",platformLoginList.get(0).get("linkman"));
                        map.put("onlineTime",loginTimeInt);
                        mapList.add(map);
                    }
                }
                log.info("在线用户数:" + userOnlineList.size());
            }
            Map map1=new HashMap();
            map1.put("OnlineUsers", userOnlineList.size());
            mapList.add(map1);
            response.setData(mapList);
            response.setCode(RetCode.SUCCESS);
            response.setMsg("执行成功");
        }catch (Exception e){
            e.printStackTrace();
        }

        return response;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/deleteQuitUser")
    @ApiOperation(value = "删除退出用户的登录时间", notes = "删除退出用户的登录时间", httpMethod = "POST")
    public void deleteQuitUser(HttpServletRequest request){
        try {
            final String authHeader = request.getHeader(JwtTokenUtil.AUTH_HEADER_KEY);
            String sessionId=authHeader.replaceAll("Bearer ","");
            loginTimeMapper.deleteByPrimaryKey(sessionId);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
